<template>
    <h3>显示列表信息</h3>
    投资名称：<input type="text" v-model="I_Name">
    投资总额度：<input type="text" v-model="Max">--
    <input type="text" v-model="Min">
    <table>
        <thead>
            <tr>
                <td>投资名称</td>
                <td>投资总额度</td>
                <td>已投资额度</td>
                <td>剩余额度</td>
                <td>投资人数</td>
                <td>操作</td>
            </tr>
        </thead>
        <thead>
            <tr v-for="item in str" :key="item.I_Id" :value="item.I_Id">
                <td>{{ item.I_Name }}</td>
                <td>{{ item.PriceAll }}</td>
                <td>{{ item.PriceYi }}</td>
                <td>{{ item.PriceSheng }}</td>
                <td>{{ item.Num }}</td>
                <td><button @click="Del(item.I_Id)">删除</button>
                    <button>修改</button>
                </td>
            </tr>
        </thead>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router';
import axios from 'axios';
import { onMounted } from 'vue';

const I_Name = ref("");
const Max = ref();
const Min = ref();
const str = ({
    I_Id: 0,
    I_Name: "",
    PriceAll: 0,
    PriceYi: 0,
    PriceSheng: 0,
    Num: 0
})

onMounted()=> {
    ShowInvest();
}

const ShowInvest = () => {
    axios.get('http://localhost:65052/api/Invest/ShowInvest', {
        params: {
            name: I_Name.value,
            MaxPriceAll: Max.value,
            MinPriceAll: Min.value
        }
    })
        .then(res => {
            res.data = str.value
        })
        .catch(error => {
            console.log(error);
        })
}
const Del(I_Id: number) => {
    axios.get('http://localhost:65052/api/Invest/Delete', {
        params: {
            i_Id: I_Id
        }
    })
        .then(res => {
            if (res.data > 0) {
                alert("删除成功");
                Jump();
            }
            else {
                alert("删除失败")
                return;
            }
        })
        .catch(error => {
            console.log(error);
        })
}
const router = useRouter();
const Jump = () => {
    router.push({
        name: 'InvestUdate'
    })
}
</script>